import logging
import typing
import ipywidgets as widgets
import src.utils.dirs as dirs
from src.mod import Interface
import src.utils.stream as stream


logger = logging.getLogger()


class ParamsInterface(Interface):
    name: typing.ClassVar[str] = "Параметры"

    def __init__(self, config, params) -> None:
        super().__init__(config, params)

        self.textarea = widgets.Textarea(
            layout={
                'width': '80%',
                'border': '2px solid blue',
                'grid_area': 'textarea'
            },
            rows=10
        )
        self.btn_create = widgets.Button(
            description='Создать из параметров по умолчанию',
            layout={'width': '50%', 'grid_area': 'btn_create'}
        )
        self.btn_save = widgets.Button(
            description='Сохранить',
            layout={'width': 'auto', 'grid_area': 'btn_save'})
        self.btn_delete = widgets.Button(
            description='Очистить',
            layout={'width': 'auto', 'grid_area': 'btn_delete'})

        self.btn_dropdown = widgets.Dropdown(
            options=['YAML', 'JSON'],
            value='YAML',
            description='Выберите тип файла:',
            disabled=False,
            layout={
                'width': 'auto',
                'grid_area': 'btn_dropdown'
            }
        )
        self.btn_create.on_click(self.save)
        self.btn_delete.on_click(self.delete)
        self.btn_save.on_click(self.save)

        self.children = [
            self.btn_save, self.btn_delete,
            self.btn_create, self.btn_dropdown,
            self.textarea
        ]
        self.box = widgets.GridBox(
            self.children,
            layout={
                'grid_template_rows': 'auto auto auto auto',
                'grid_template_areas': '''
                "btn_create btn_dropdown btn_dropdown"
                "textarea textarea textarea btn_save"
                "textarea textarea textarea btn_delete"
                '''}
        )

    def create(self, call):
        if not self.textarea.value:
            self.output
        if not self.btn_dropdown.value:
            self.output

    def save(self, call):
        ...

    def delete(self, call):
        ...
